<template>
  <div class="order">
    <x-header title="订单列表" :left-options="{backText:'',preventGoBack:true}" @click.native='goMine' class='whiteHeader'>
      <a :href="'tel:'+phone" slot='right'>
        <img src="../../assets/image/order/phone.png" class="phone">
      </a>
    </x-header>
    <tab :line-width='2' active-color='#EC2121' v-model="selectIndex">
        <tab-item class="vux-center" v-for="(item,index) in list" @click.native="selectItem(index)" :key="index">{{item}}</tab-item>
	</tab>
	<scroller :on-infinite="infinites" class='myScroller' ref='myScroller' :on-refresh="refresh" :loadingLayerColor='loadColor'>
	  <div class="allOrder">
        <div class="orderItem" v-for='(item,index) in orderMess[selectIndex].order' :key='index'>
          <div class="shopName border-bottom">
            <img src="../../assets/image/shopLogo.png" alt="" />
            <h1>{{item.SHOP_NAME}}</h1>
            <span class="orderType" v-if='item.orderType==1' style="color:#F22E2E;">待付款</span>
            <span class="orderType" v-if='item.orderType==2' style="color:#FF8C05;">拼团中，已付款</span>
            <span class="orderType" v-if='item.orderType==3' style="color:#66CC22;">拼团成功，已付款</span>
            <span class="orderType" v-if='item.orderType==4' style="color:#66CC22;">拼团成功，待开奖 </span>
            <span class="orderType" v-if='item.orderType==5' style="color:#F22E2E;">一等奖，待收货</span>
            <span class="orderType" v-if='item.orderType==6' style="color:#999999;">拼团失败，退款中</span>
            <span class="orderType" v-if='item.orderType==7' style="color:#999999;">拼团失败，已退款</span>
            <span class="orderType" v-if='item.orderType==8' style="color:#F22E2E;">二等奖，退款中并送券</span>
            <span class="orderType" v-if='item.orderType==9' style="color:#F22E2E;">二等奖，已退款并送券</span>
            <span class="orderType" v-if='item.orderType==10' style="color:#66CC22;">拼团成功，待评价</span>
            <span class="orderType" v-if='item.orderType==11' style="color:#66CC22;">拼团成功，已完成</span>
            <span class="orderType" v-if='item.orderType==12' style="color:#F22E2E;">待服务</span>
            <span class="orderType" v-if='item.orderType==13' style="color:#66CC22;">待评价</span>
            <span class="orderType" v-if='item.orderType==14' style="color:#999999;">已过期</span>
            <span class="orderType" v-if='item.orderType==15' style="color:#66CC22;">已完成</span>
          </div>
          <div class="allShop" @click='goOrderDetail(item)'>
            <div class="shop border-bottom" v-for="items in item.DETAIL_LIST" v-if="item.DETAIL_LIST[0].FIRST_CLASS!=10001&&item.DETAIL_LIST[0].FIRST_CLASS!=10003">
              <div class="groupLogo" v-if='item.ACT_TYPE=="17092852"'></div>
              <img :src="items.COVER_IMG" alt="" />
              <div class="shopMess">
                <h2>{{items.D_SUBJECT}}<span class="price">￥{{items.sum}}</span></h2>
                <div class="Spec">
                  <p>
                	<span v-if='items.QUANTITY'>数量{{items.QUANTITY}}</span>
                	<span v-if='items.ATTR_LIST' v-for='itemss in items.ATTR_LIST'>{{itemss.TYPE}}:{{itemss.D_SUBJECT}}</span>
                  </p>
                </div>
              </div>
            </div>
            <div class="shop border-bottom" v-if="item.DETAIL_LIST[0].FIRST_CLASS==10001||item.DETAIL_LIST[0].FIRST_CLASS==10003">
              <img :src="item.DETAIL_LIST[0].COVER_IMG" alt="" />
              <div class="shopMess">
                <h2 v-if="item.DETAIL_LIST[0].FIRST_CLASS==10001">{{item.DETAIL_LIST[0].PACKAGE_NAME}}</h2>
                <h2 v-if="item.DETAIL_LIST[0].FIRST_CLASS==10003">{{item.DETAIL_LIST[0].D_SUBJECT}}<span v-if='item.DETAIL_LIST.length>1'>等</span></h2>
                <div class="Spec">
                  <p>
                  <span>共计{{item.DETAIL_LIST.length}}个部位</span>
                  </p>
                  <!-- <span class="price">￥{{item.TOTAL_PRICE}}</span> -->
                </div>
              </div>
            </div>
          </div>
          <div class="orderC border-bottom">
          	<p v-if='item.DETAIL_LIST&&(item.DETAIL_LIST[0].FIRST_CLASS!=10001&&item.DETAIL_LIST[0].FIRST_CLASS!=10003)'>共计{{item.num}}件商品 实付款：</p>
            <p v-if='item.DETAIL_LIST&&(item.DETAIL_LIST[0].FIRST_CLASS==10001||item.DETAIL_LIST[0].FIRST_CLASS==10003)'>共计{{item.num}}个部位 实付款：</p><span>￥{{item.TOTAL_PRICE}}</span>
          </div>
          <div class="orderBtn" v-if='(item.STATUS==2&&(item.PAY_STATUS==0||item.PAY_STATUS==1))||(item.STATUS==3&&item.PAY_STATUS==1)||(item.STATUS==4)'>
            <!-- 活动商品距开抢时间 -->
            <div class="activeTime" v-if='item.downObj.flag&&item.AVL_PAY_TIME>0'>距开抢<span>{{item.downObj.D}}</span>天<span>{{item.downObj.H}}</span>时<span>{{item.downObj.M}}</span>分<span>{{item.downObj.S}}</span>秒</div>
          	<div class="btns" v-if='(item.STATUS==2&&item.PAY_STATUS==0)&&(item.CLOSE_TIME==0||item.AVL_PAY_TIME>0)' @click='goPay(item)'>去支付</div>
            <!-- 已完成 -->
            <!-- <div class="btns finish" v-if='item.STATUS==4&&item.PAY_STATUS==1' @click='goOrderDetail(item)'>已完成</div> -->
            <!-- 支付剩余时间 -->
            <div class="btns downs" v-if='(item.STATUS==2&&item.PAY_STATUS==0)&&(item.downObj.flag&&item.AVL_PAY_TIME==0)' @click='goPay(item)'>去支付(还剩<span v-if='(Number(item.downObj.D*24)+Number(item.downObj.H))>0'>{{Number(item.downObj.D*24)+Number(item.downObj.H)}}小时</span>{{Number(item.downObj.M)}}分{{item.downObj.S}}秒)</div>
            <!-- <div class="btns finish" v-if='item.STATUS==2&&item.PAY_STATUS==1' @click='goOrderDetail(item)'>已支付</div> -->
          	<div class="btns" v-if='item.STATUS==3&&item.PAY_STATUS==1' @click="goComment(item)">去评价</div>
          </div>
        </div>
      </div>
    </scroller>
    <toast v-model="showNoOrder" type="text" text="暂无最新订单" position='top'></toast>
    <div class="noData" v-if='orderMess[selectIndex].order.length==0&&pages[selectIndex].page>1'>
      <img src="../../assets/image/order/noData.png" alt="" />
      <p>{{texts[selectIndex]}}</p>
    </div>
  </div>
</template>
<script>
/*智能保养*/
import {XHeader , Tab, TabItem,Toast  } from 'vux';
import { setCookie, getCookie } from '../../util/commonUtils';
export default {
  name:"order",
  // 数据
  data(){
    return{
    	userId:'',//用户id
    	list:['全部订单','待服务','待付款','待评价','已完成'],
    	selectIndex:0,//选择的选项
      texts:['暂无订单','暂无待服务订单','暂无待付款订单','暂无待评价订单','暂无已完成订单'],
    	type:['TOTAL_ORDER','WAIT_SERV','WAIT_PAY','WAIT_EVALUATE','ORDER_FINISH'],//订单状态
    	// 所有订单 待服务订单 待付款订单 待评价订单 已完成订单
    	orderMess:[{order:[]},{order:[]},{order:[]},{order:[]},{order:[]}],
    	//所有订单状态 相应请求页面
    	pages:[{page:1,flag:false},{page:1,flag:false},{page:1,flag:false},{page:1,flag:false},{page:1,flag:false}],//每个状态请求的页数和数据状态
      showNoOrder:false,
      phone:'', //服务电话
      flag:true,  //倒计时状态
      loadColor:'#efeff4',
      oneRequest:false  
    }
  },
  // 计算属性
  computed:{
    //倒计时
  },
  // 创建（实例创建完成）
  created(){
    this.userId=getCookie('loginkey');
    this.selectIndex=Number(this.$route.params.id);
    setInterval(()=>{
      this.checkAllOrder();
    },500)
  },
  // el被创建，并挂载到实例上
  mounted(){

  },
  beforeRouteLeave (to, from, next) {
    // 导航离开该组件的对应路由时调用
    // 可以访问组件实例 `this`
    this.$vux.loading.hide();
    next();
  },
  // 方法（实例中的方法）-----------
  methods:{
  	//更换不同订单状态
    selectItem(index){
    	this.selectIndex=index;
    	this.flag=false;
    	this.infinites();
    	//订单状态切换
    },
    goMine(){
      this.$router.push('/mine');
    },
    // 计算时间
    computerTime(activeTime,closeTime){
      let times=new Date().getTime();//当前时间
      let D,H,M,S;
      let cTime;
      if(activeTime>0){
        cTime=activeTime;
        this.flag=true;
      }else{
        cTime=closeTime;
        this.flag=true;
      }
      let timeNum=cTime-times;
      if(timeNum>=0){
        D=parseInt(timeNum/(24*3600*1000));
        H=parseInt((timeNum-D*24*3600*1000)/(3600*1000));
        M=parseInt((timeNum-D*24*3600*1000-H*3600*1000)/(60*1000));
        S=parseInt((timeNum-D*24*3600*1000-H*3600*1000-M*60*1000)/1000);
      }else{
        D=0;
        H=0;
        M=0;
        S=0;
        if(activeTime>0){
          this.flag=true;
        }else{
          this.flag=false;
        }
      }
      D=this.filterNum(D);
      H=this.filterNum(H);
      M=this.filterNum(M);
      S=this.filterNum(S);
      return{
        flag:this.flag,
        D:D,
        H:H,
        M:M,
        S:S
      }
    },
    //轮询所有的订单
    checkAllOrder(){
      for(let i=0;i<this.orderMess.length;i++){
        if(i==0||i==2){
          for(let j=0;j<this.orderMess[i].order.length;j++){
            if(this.orderMess[i].order[j].AVL_PAY_TIME>0||this.orderMess[i].order[j].CLOSE_TIME>0){
              let downObj=this.computerTime(this.orderMess[i].order[j].AVL_PAY_TIME,this.orderMess[i].order[j].CLOSE_TIME);
              if(downObj.D==0&&downObj.H==0&&downObj.M==0&&downObj.S==0&&(this.orderMess[i].order[j].AVL_PAY_TIME==0&&this.orderMess[i].order[j].CLOSE_TIME>0)){
                this.orderMess[i].order.splice(j,1);
              }
              this.orderMess[i].order[j].downObj=downObj;
            }
          }
        }
      }
    },
    //过滤时间
    filterNum(num){
      return num>=10?num:'0'+num;
    },
    computedNumPrice(result){
      let arr=result;
      for(let i=0;i<arr.length;i++){
        let num=0;
        let firstClass=arr[i].DETAIL_LIST[0].FIRST_CLASS;
        for(let j=0;j<arr[i].DETAIL_LIST.length;j++){
          let sum=0;
          sum+=Number(arr[i].DETAIL_LIST[j].PRICE);
          num+=Number(arr[i].DETAIL_LIST[j].QUANTITY);
          for(let m=0;m<arr[i].DETAIL_LIST[j].ATTR_LIST.length;m++){
            sum+=Number(arr[i].DETAIL_LIST[j].ATTR_LIST[m].PRICE);
          }
          arr[i].DETAIL_LIST[j].sum=sum;
        }
        let downObj=this.computerTime(arr[i].AVL_PAY_TIME,arr[i].CLOSE_TIME);
        arr[i].downObj=downObj;
        arr[i].FIRST_CLASS=firstClass;
        arr[i].num=num;
        if (arr[i].STATUS == 2 && arr[i].PAY_STATUS == 1) {//待服务
            arr[i].orderType=12;
        } else if (arr[i].STATUS ==3 && arr[i].PAY_STATUS == 1) {//待评价
            arr[i].orderType=13;
        } else if (arr[i].STATUS ==6 && arr[i].PAY_STATUS == 1) {//已过期
            arr[i].orderType=14;
        } else if(arr[i].STATUS ==4 && arr[i].PAY_STATUS == 1){//已完成
            arr[i].orderType=15;
        }

        if(arr[i].STATUS==2&&arr[i].PAY_STATUS==0){//待付款
          arr[i].orderType=1;
        }else if(arr[i].STATUS==2&&arr[i].PAY_STATUS==1&&(arr[i].GROUPON_TYPE==1||arr[i].GROUPON_TYPE==2||arr[i].GROUPON_TYPE==3)&&arr[i].GROUPON_STATUS==2){//拼团中，已付款
          arr[i].orderType=2;
        }else if(arr[i].STATUS==2&&arr[i].PAY_STATUS==1&&(arr[i].GROUPON_TYPE==1||arr[i].GROUPON_TYPE==3)&&arr[i].GROUPON_STATUS==1){//拼团成功，已付款
          arr[i].orderType=3;
        }else if(arr[i].STATUS==2&&arr[i].PAY_STATUS==1&&arr[i].GROUPON_TYPE==2&&arr[i].GROUPON_STATUS==1&&arr[i].PRIZE_STATUS==0){//拼团成功，待开奖
          arr[i].orderType=4;
        }else if(arr[i].STATUS==2&&arr[i].PAY_STATUS==1&&arr[i].GROUPON_TYPE==2&&arr[i].GROUPON_STATUS==1&&arr[i].PRIZE_STATUS==1&&arr[i].PRIZE_LEVEL==1){//拼团成功，已开奖
          arr[i].orderType=5;
        }else if(arr[i].STATUS==7&&arr[i].PAY_STATUS==1&&(arr[i].GROUPON_TYPE==1||arr[i].GROUPON_TYPE==2||arr[i].GROUPON_TYPE==3)&&arr[i].GROUPON_STATUS==0){//拼团失败，退款中
          arr[i].orderType=6;
        }else if(arr[i].STATUS==8&&arr[i].PAY_STATUS==1&&(arr[i].GROUPON_TYPE==1||arr[i].GROUPON_TYPE==2||arr[i].GROUPON_TYPE==3)&&arr[i].GROUPON_STATUS==0){//拼团失败，已退款
          arr[i].orderType=7;
        }else if(arr[i].STATUS==7&&arr[i].PAY_STATUS==1&&arr[i].GROUPON_TYPE==2&&arr[i].GROUPON_STATUS==1&&arr[i].PRIZE_STATUS==1&&arr[i].PRIZE_LEVEL>=2){//已开奖，退款中
          arr[i].orderType=8;
        }else if(arr[i].STATUS==8&&arr[i].PAY_STATUS==1&&arr[i].GROUPON_TYPE==2&&arr[i].GROUPON_STATUS==1&&arr[i].PRIZE_STATUS==1&&arr[i].PRIZE_LEVEL>=2){//已开奖，已退款
          arr[i].orderType=9;
        }else if(arr[i].STATUS==3&&arr[i].PAY_STATUS==1&&(arr[i].GROUPON_TYPE==1||arr[i].GROUPON_TYPE==2||arr[i].GROUPON_TYPE==3)&&arr[i].GROUPON_STATUS==1){//拼团成功，待评价
          arr[i].orderType=10;
        }else if(arr[i].STATUS==4&&arr[i].PAY_STATUS==1&&(arr[i].GROUPON_TYPE==1||arr[i].GROUPON_TYPE==2||arr[i].GROUPON_TYPE==3)&&arr[i].GROUPON_STATUS==1){//拼团成功，已评价
          arr[i].orderType=11;
        }
        // else if(arr[i].STATUS==2&&arr[i].PAY_STATUS==1&&arr[i].GROUPON_STATUS==0){//拼团失败，退款中
        //   arr[i].orderType=6;
        // }
      }
      return arr;
    },
    //获取所有订单（第一次）
    getOrder(){
    	let obj={};
      this.oneRequest=true;
    	obj.USER_ID=this.userId;
    	obj.TYPE=this.type[this.selectIndex];
    	obj.PAGE_NO=1;
      this.loadColor='#efeff4';
      this.$vux.loading.show({
       text: ''
      });
    	this.$fetchPost('/ServOrderWeb/getUserOrderList.action',obj).then(res=>{
          if(res.STATUS_CODE==1){
            this.oneRequest=false;
            this.$vux.loading.hide();
            this.pages[this.selectIndex].page++;
          	if(res.RESULT_DATA.length==0){
          		this.$refs.myScroller.finishInfinite(2);//通知scroller数据全部加载完成
          		this.pages[this.selectIndex].flag=true;
              document.getElementsByClassName('no-data-text')[0].style.color='#efeff4';
          		return;
          	}
            this.phone=res.SERV_PHONE;
          	// this.orderMess[this.selectIndex].order=res.RESULT_DATA; 
            this.orderMess[this.selectIndex].order=this.computedNumPrice(res.RESULT_DATA);
          	this.$refs.myScroller.finishInfinite();//通知scroller数据已经加载完成
          }
        },err=>{
          console.log(err);
        })
    },
    //上拉刷新
    getMordeOrder(){
      this.loadColor='#aaa';
      this.oneRequest=true;
    	if(this.pages[this.selectIndex].flag){
    		this.$refs.myScroller.finishInfinite(2);
    		return;
    	}
    	let obj={};
    	obj.USER_ID=this.userId;
    	obj.TYPE=this.type[this.selectIndex];
    	obj.PAGE_NO=this.pages[this.selectIndex].page;
    	this.$fetchPost('/ServOrderWeb/getUserOrderList.action',obj).then(res=>{
          if(res.STATUS_CODE==1){
            this.oneRequest=false;
          	if(res.RESULT_DATA.length==0){
          		this.pages[this.selectIndex].flag=true;
          		this.$refs.myScroller.finishInfinite(2);
              document.getElementsByClassName('no-data-text')[0].style.color='#aaa';
          		return;
          	}
          	this.$refs.myScroller.finishInfinite();
          	this.pages[this.selectIndex].page++;
          	this.orderMess[this.selectIndex].order=this.orderMess[this.selectIndex].order.concat(this.computedNumPrice(res.RESULT_DATA));
          }
        },err=>{
          console.log(err);
        })
    },
    infinites(){
    	if(this.pages[this.selectIndex].page>1){
        if(!this.oneRequest){
          this.getMordeOrder();
        }
			  
    	}else{
        if(!this.oneRequest){
    		  this.getOrder();
        }
    	}
    },
    //下拉更新
    refresh(){
      this.loadColor='#aaa';
      let obj={};
      if(this.pages[this.selectIndex].page<=1){
        return;
      }
      obj.USER_ID=this.userId;
      obj.TYPE=this.type[this.selectIndex];
      obj.PAGE_NO=1;
      this.$fetchPost('/ServOrderWeb/getUserOrderList.action',obj).then(res=>{
          if(res.STATUS_CODE==1){
            let len=this.orderMess[this.selectIndex].order.length;
            this.orderMess[this.selectIndex].order=this.unquie(this.orderMess[this.selectIndex].order,this.computedNumPrice(res.RESULT_DATA));
            let len2=this.orderMess[this.selectIndex].order.length;
            if(len==len2){
              this.showNoOrder=true;
              setTimeout(function(){
                this.showNoOrder=false;
              },2000)
            }
            this.$refs.myScroller.finishPullToRefresh();//通知加载完成
          }
        },err=>{
          console.log(err);
        })
    },
    //去订单详情
    goOrderDetail(item){
      if(item.ACT_TYPE === 17092852){
        this.$router.push('/gOrderDetail/'+item.ORDER_ID);
      }else{
        this.$router.push('/orderDetail/'+item.ORDER_ID);
      }
    },
    //去支付
    goPay(item){
      // console.log(JSON.stringify(item));
      if(item.FIRST_CLASS==10007||item.FIRST_CLASS==10002){//美容和车品
        this.productCos(item);
      }else if(item.FIRST_CLASS==10003){//喷漆
        this.spray(item);
      }else if(item.FIRST_CLASS==10008){//咖啡
        this.cafe(item);
      }else if(item.FIRST_CLASS==6565){//保养年卡购买
        this.maintainCard(item);
      }else{//保养，违章
        this.mainIllegal(item);
      }
    },
    //美容和车品支付数据的封装
    productCos(item){
      let obj={};
      obj.address=[{}]
      obj.address[0].CONTACT=item.CONTACT;
      obj.address[0].PHONE=item.CONTACT;
      obj.address[0].detailAddress=item.ADDRESS;
      obj.ORDER_ID=item.ORDER_ID;
      obj.USER_ID=this.userId;
      obj.VOUCHERS_AMOUNT=item.VOUCHERS_AMOUNT;
      obj.selectCars=[{}];
      obj.selectCars[0].LICENCE=item.CAR_NUMBER;
      obj.selectCars[0].BRAND=item.CAR_BRAND_NAME.split('_')[0];
      obj.selectCars[0].SET=item.CAR_BRAND_NAME.split('_')[1];
      obj.selectCars[0].MODEL=item.CAR_BRAND_NAME.split('_')[2];
      obj.sum=String(item.TOTAL_PRICE);
      obj.TB_NUM=item.TB_NUM;
      obj.ORDER_LIST=[];
      for(let i=0;i<item.DETAIL_LIST.length;i++){
        let objs={};
        objs.COMP_ID=item.COMP_ID;
        objs.SHOP_NAME=item.SHOP_NAME;
        objs.CASH_VOL_NO=item.VOUCHERS_NO;
        objs.SERV_PARAMS=[];
        let objss={};
        objss.SERV_ID=item.DETAIL_LIST[i].SERV_ID;
        objss.SERV_SUBJECT=item.DETAIL_LIST[i].D_SUBJECT;
        objss.PRICE=item.DETAIL_LIST[i].SINGLE_PRICE;
        objss.QUANTITY=item.DETAIL_LIST[i].QUANTITY;
        objss.SUPP_CASH_VOL=item.DETAIL_LIST[i].SUPP_CASH_VOL;
        objss.SUPP_DIS_VOL=item.DETAIL_LIST[i].SUPP_DIS_VOL;
        objss.SUPP_NOR_CASH_VOL=item.DETAIL_LIST[i].SUPP_NOR_CASH_VOL;
        objss.SERV_FIRST_CLASS=item.DETAIL_LIST[i].FIRST_CLASS;
        objss.SERV_SECON_CLASS=item.DETAIL_LIST[i].SECON_CLASS;
        objss.MARK=1;
        objss.ATTR_LIST=[];
        for(let j=0;j<item.DETAIL_LIST[i].ATTR_LIST.length;j++){//封装商品属性
          let objsss={};
          objsss.TYPE=item.DETAIL_LIST[i].ATTR_LIST[j].TYPE;
          objsss.ATTRIBURE=item.DETAIL_LIST[i].ATTR_LIST[j].SERV_ID;
          objss.PRICE=Number(objss.PRICE)+Number(item.DETAIL_LIST[i].ATTR_LIST[j].SINGLE_PRICE);
          objss.ATTR_LIST.push(objsss);
        }
        objs.SERV_PARAMS.push(objss);
        obj.ORDER_LIST.push(objs);
      }
      sessionStorage.removeItem('orderMess');
      sessionStorage.removeItem('distribuVoucher');
      //存储支付页面需要的信息 
      sessionStorage.setItem('shopMess',JSON.stringify(obj));
      localStorage.setItem('from','order');//代表车品来自订单
      this.$router.push('/shopPay');
    },
    //喷漆数据的封装
    spray(item){
        let obj={};
        obj.USER_ID=this.userId;
        obj.ORDER_ID=item.ORDER_ID;
        obj.SHOP_NAME=item.SHOP_NAME;
        obj.CAR_NUMBER=JSON.parse( localStorage.getItem("defaultCatAllInfo") ).LICENCE;
        obj.VOUCHERS_AMOUNT=item.VOUCHERS_AMOUNT;
        obj.TB_NUM=item.TB_NUM;
        obj.TOTAL_PRICE=item.TOTAL_PRICE;
        obj.ORDER_LIST=[];
        let objs={};
        objs.COMP_ID=item.COMP_ID;
        objs.CASH_VOL_NO=item.VOUCHERS_NO;
        objs.STARTTIME=item.PREDATE_START;
        objs.ENDTIME=item.PREDATE_END;
        objs.SERV_PARAMS=[];
        for(let i=0;i<item.DETAIL_LIST.length;i++){
          let objss={};
          objss.SERV_ID=item.DETAIL_LIST[i].SERV_ID;
          objss.MT_DETAIL_NAME=item.DETAIL_LIST[i].D_SUBJECT;
          objss.PRICE=item.DETAIL_LIST[i].PRICE;
          objss.QUANTITY=1;
          objss.MARK=0;
          objs.SERV_PARAMS.push(objss);
          
        }
        obj.ORDER_LIST.push(objs);
        sessionStorage.removeItem('orderMess');
        //存储支付页面需要的信息 
        sessionStorage.setItem('payMess',JSON.stringify(obj));
        localStorage.setItem('fromOrder','spray');
        localStorage.setItem('from','maintain');//代表支付来自钣喷
        this.$router.push('/pay');
    },
    //咖啡支付数据的封装
    cafe(item){
      // localStorage.setItem("orderMess",JSON.stringify(item));
      // localStorage.removeItem("shopOrderMess");
      // //清除上一次选择代金券存储的信息
      // localStorage.removeItem("CASH_VOL_NO");//代金券号
      // localStorage.removeItem("CASH_VOLUME_ID");//代金券的id
      // localStorage.removeItem('voucherMessage');//清除选择代金券存储的代金券信息
      // localStorage.removeItem("fromSelect");//清除来自代金券选择的标识;
      //跳转到4scafe的支付页面
      if(this.userId){//登录情况下
          location.href='http://4Scafe.carnettong.com/4SCAFE/HTML5/aTestWx/dist/index.html?phone='+getCookie('userName');
      }else{
          location.href='http://4Scafe.carnettong.com/4SCAFE/HTML5/aTestWx/dist/index.html'
      }
      // if(this.userId){//登录情况下
      //     location.href='http://carnt.carnettong.com:8088/4SCAFE/HTML5/aTestWx/dist/index.html?phone='+getCookie('userName');
      // }else{
      //     location.href='http://carnt.carnettong.com:8088/4SCAFE/HTML5/aTestWx/dist/index.html'
      // }
    },
    //保养年卡购买数据的封装
    maintainCard(item){
      let obj={};
      obj.USER_ID=this.userId;
      obj.SHOP_NAME=item.SHOP_NAME;
      obj.ORDER_ID=item.ORDER_ID;
      obj.TOTAL_PRICE=item.TOTAL_PRICE;
      obj.ORDER_LIST=[];
      let objs={};
      objs.COMP_ID=item.COMP_ID;
      objs.SERV_PARAMS=[];
      for(let i=0;i<item.DETAIL_LIST.length;i++){
        let objss={};
        objss.SERV_ID=item.DETAIL_LIST[i].SERV_ID;
        objss.MT_DETAIL_NAME=item.DETAIL_LIST[i].D_SUBJECT;
        objss.PRICE=item.DETAIL_LIST[i].PRICE;
        objss.QUANTITY=1;
        objss.MARK=0;
        objs.SERV_PARAMS.push(objss);
      }
      obj.ORDER_LIST.push(objs);
      sessionStorage.removeItem('orderMess');
      // //存储支付页面需要的信息 
      sessionStorage.setItem('payMess',JSON.stringify(obj));
      localStorage.setItem('fromOrder','maintainCard');
      localStorage.setItem('from','maintain');//代表支付来自保养
      this.$router.push('/pay');
    },
    //保养，违章支付数据的封装
    mainIllegal(item){
      if(item.FIRST_CLASS==10001){//保养支付数据，查看接口就能知道数据对应的字段
        let obj={};
        obj.USER_ID=this.userId;
        obj.ORDER_ID=item.ORDER_ID;
        obj.SHOP_NAME=item.SHOP_NAME;
        obj.HOUR_TOTAL_FEE='';
        obj.CAR_NUMBER=item.CAR_NUMBER;
        obj.CAR_BRAND_NAME=item.CAR_BRAND_NAME;
        obj.MILEAGE=item.MILEAGE
        obj.VOUCHERS_AMOUNT=item.VOUCHERS_AMOUNT;
        obj.TB_NUM=item.TB_NUM;
        obj.TOTAL_PRICE=item.TOTAL_PRICE;
        obj.ORDER_LIST=[];
        let objs={};
        objs.COMP_ID=item.COMP_ID;
        objs.CASH_VOL_NO=item.VOUCHERS_NO;
        objs.STARTTIME=item.PREDATE_START;
        objs.ENDTIME=item.PREDATE_END;
        objs.SERV_PARAMS=[];
        for(let i=0;i<item.DETAIL_LIST.length;i++){
          let objss={};
          objss.SERV_ID=item.DETAIL_LIST[i].SERV_ID;
          objss.MT_DETAIL_NAME=item.DETAIL_LIST[i].D_SUBJECT;
          objss.PRICE=item.DETAIL_LIST[i].PRICE;
          objss.QUANTITY=1;
          objss.MARK=0;
          if(item.DETAIL_LIST[i].SERV_ID==0){
            obj.HOUR_TOTAL_FEE=item.DETAIL_LIST[i].PRICE;
          }else{
            objs.SERV_PARAMS.push(objss);
          }
        }
        obj.ORDER_LIST.push(objs);
        sessionStorage.removeItem('orderMess');
        //存储支付页面需要的信息 
        sessionStorage.setItem('payMess',JSON.stringify(obj));
        localStorage.setItem('fromOrder','maitain');
        localStorage.setItem('from','maintain');//代表支付来自保养
        this.$router.push('/pay');
      }else if(item.FIRST_CLASS==709394){
        let obj={}
        obj.COMP_ID=item.COMP_ID;
        obj.QUANTITY=1;
        obj.CAR_NUMBER=item.CAR_NUMBER;
        obj.allPRICE=item.TOTAL_PRICE;
        obj.MOBILE_PHONE=item.USER_PHONE;
        obj.ORDER_ID=item.ORDER_ID;
        obj.TB_NUM=item.TB_NUM;
        obj.SERV_NAME=item.DETAIL_LIST[0].D_SUBJECT;
        obj.SHOP_NAME=item.SHOP_NAME;
        sessionStorage.removeItem('orderMess');
        sessionStorage.setItem('payMess',JSON.stringify(obj));
        localStorage.setItem('fromOrder','illegal');
        localStorage.setItem('from','illegal');//代表支付来自保养
        this.$router.push('/pay');
      }
    },
    // 去评价
    goComment(item){
      localStorage.setItem('commentMess',JSON.stringify(item));
      this.$router.push('/comment/'+item.ORDER_ID);
    },
    //合并两个数组，并去除掉重复项
    unquie(arr1, arr2){ 
     for (var i = 0 ; i < arr1.length ; i ++ ){
       for(var j = 0 ; j < arr2.length ; j ++ ){
        if (arr1[i].ORDER_ID === arr2[j].ORDER_ID){
         arr2.splice(i,1); //利用splice函数删除元素，从第i个位置，截取长度为1的元素
        }
       }
     }
     for(var i = arr2.length-1; i <=0; i--){
        arr1.unshift(arr2[i]);
     }
     return arr1;
    }
  },
  // 子组件
  components:{
    XHeader,
    TabItem,
    Tab,
    Toast 
  }
}
</script>
<!--当前页面的样式 -->
<style lang="less" scoped>

.order{
  width: 7.5rem;
  height: 100%;
  margin-bottom: 1.7rem;
  .myScroller{
  	top: 1.7rem;
  }
  .noData{
    width: 2.1rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform:translate(-50%,-50%);
    img{
      display: block;
      width: 1.8rem;
      height: 1.8rem;
      margin: 0 auto;
    }
    p{
      font-size: 0.25rem;
      margin-top: 0.35rem;
      color: #666;
    }
  }
  .phone{
    width: 0.45rem;
    height: 0.41rem;
  }
  .tab-swiper{
  	font-size: 0.3rem;
  }
  .allOrder{
    .orderItem{
    	border-bottom: 0.2rem solid #ebebeb;
      background: #fff;
      .shopName{
        font-size: 0.3rem;
        height: 0.8rem;
        line-height: 0.8rem;
        text-align: left;
        display: flex;
        img{
          width: 0.4rem;
          height: 0.4rem;
          margin: 0.2rem;
          vertical-align: middle;
        }
        h1{
        	font-size: 0.28rem;
        	width: 70%;
        }
        span{
        	width: 58%;
          text-align: right;
          font-size: 0.28rem;
          padding-right: 0.1rem;
          color:#ec2121;
        }
        overflow:hidden;
      }
      .shop{
      	background: #f5f5f5;
        display: flex;
        padding: 0.2rem 0.3rem;
        position: relative;
        .groupLogo{
            width: 0.4rem;
            height: 0.46rem;
            background: url(../../assets/image/order/groupLogo.png) no-repeat;
            background-size: 0.4rem 0.46rem;
            position: absolute;
            top: 0.15rem;
            left: 0.2rem;
        }
        img{
            width: 1.5rem;
            height: 1.5rem;
            min-width: 1.5rem;
            display: block;
        }
        .shopMess{
    			width: 80%;
    			padding-left: 0.3rem;
    			text-align: left;
          h2{
            font-size: 0.28rem;
            margin:0.2rem 0;
            overflow: hidden;
            overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
            width: 98%;
            .price{
              float: right;
              font-size: 0.32rem;
            }
          }
          .Spec{
          	padding-top: 0.2rem;
            font-size: 0.23rem;
            color: #333;
            display: flex;
            justify-content:space-between;
            p{
              width: 70%;
            }
            span{
            	padding-right: 0.1rem;
            }

          }
        }
      }
      .orderC{
      	display: flex;
      	height: 1rem;
      	line-height: 1rem;
      	justify-content:flex-end;
      	p{
      		font-size: 0.28rem;
      	}
      	span{

      		font-size: 0.36rem;
      		color: #ff0000;
      		padding-right: 0.2rem;
      	}
      }
      .orderBtn{
      	overflow: hidden;
      	.btns{
      		width: 1.2rem;
      		height: 0.6rem;
      		font-size: 0.26rem;
      		line-height: 0.6rem;
      		text-align: center;
      		background: #ff0000;
      		float: right;
      		color: #fff;
      		border-radius: 0.1rem;
      		margin-right: 0.2rem;
          margin: 0.1rem 0.2rem 0.1rem 0;
      	}
        .activeTime{
          font-size: 0.28rem;
          float: left;
          padding-left: 0.2rem;
          line-height: 1rem;
          span{
            margin:0 0.05rem;
            background: #444;
            color: #fff;
            padding: 0.1rem;
            border-radius: 0.07rem;
          }
        }
        .downs{
          width: 3.6rem;
          background: #fff;
          border:1px solid #ff0000;
          border-radius: 0.1rem;
          color: #ff0000;
        }
        .finish{
          background: #ccc;
          color: #444;
        }
      }
    }
    .orderItem:last-child{
      border:0;
    }
  }
}
</style>